package com.soccer.soccerclub.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import com.soccer.soccerclub.entity.GameOrder;
import com.soccer.soccerclub.entity.Seat;
import com.soccer.soccerclub.service.GameOrderService;
import com.soccer.soccerclub.service.SeatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-04-19
 */
@RestController
@RequestMapping("/seat")
public class SeatController {
    @Autowired
    private SeatService seatService;
    @Autowired
    private GameOrderService gameOrderService;

    /**
     * 获取区域未售出座位号
     * @param gameId
     * @param areaCode
     * @return
     */
    @GetMapping("/list")
    public R list(Integer gameId,Integer areaCode){
        List<GameOrder> gameOrderList = gameOrderService.list(new LambdaQueryWrapper<GameOrder>().eq(GameOrder::getAreaCode, areaCode).eq(GameOrder::getGameId, gameId));
        List<Integer> seatIds = new ArrayList<>();
        for (GameOrder gameOrder : gameOrderList) {
            Integer seatId = gameOrder.getSeatId();
            seatIds.add(seatId);
        }
        List<Seat> list = seatService.list(new LambdaQueryWrapper<Seat>().notIn(true, Seat::getId, seatIds));
        return R.ok(list);
    }
}

